/*
 * @Author: chunlai
 * @Date: 2023-07-25 09:48:14
 * @LastEditTime: 2025-08-22 09:33:05
 * @LastEditors: minsheng_insurance_agency_zhoucl
 * @FilePath: \02.bldinsure\src\mixins\userInfo.js
 * @Description:
 */

import { mapGetters } from "vuex";
import { countYearDayForAge, isDateString } from "@/methods/date.js";
import {
  tellPhoneFormat,
  idNumFormat,
  hasProperty,
  getCodeName,
} from "@/methods/format.js";
import { areaCodesMapping, keyNameListMapping } from "@/config/mapping.js";
import {
  nameCheckRule,
  idNumCheck,
  emailCheck,
  addrCheck,
} from "@/translate/validate/customer";

import { getBirthSex } from "@/methods/userinfos.js";
export const userInfoMix = {
  data() {
    return {
      // 用户信息
      userInfo: {
        name: "", // "姓名",
        idType: "", // "证件类型",
        idName: "",
        idNum: "", //"证件号",
        validDate: "", //"证件有效期起期",
        validDateEnd: "", //"证件有效期止期",
        sex: "", //"性别",
        birthDate: "", // "出生日期",
        age: "", //"年龄",
        height: "", //"身高",
        weight: "", //"体重",
        maritalStatus: "", // "婚姻状态",
        maritalStatusName: "",
        degree: "", // "学历",
        degreeName: "",
        phone: "", //"手机号",
        validCode: "",
        email: "", //"邮箱",
        nationality: "", // "国籍",
        nationalityName: "", //"国籍名称",
        zipCode: "", //"邮政编码",
        crsIdType: "", //"税收居民身份类型",
        crsIdTypeName: "",
        socialInsuFlag: "", // "社保标识",
        grpName: "", //"工作单位",
        partTimeJob: "", //"兼职",
        jobContent: "", //"工作内容",
        income: "", //"收入",
        incomeSource: "",
        nationCode: "",
        familyIncome: "", // "家庭年收入",
        familyIncomeSource: "", // "家庭收入来源",
        otherCompanyCompIns: "", //"是否有其他公司费用补偿型医疗险，是Y ,否N",
        occupationCode: "", // "职业编号",
        occupationClass: "",
        occupationCodeName: "",
        // 户籍地址
        rgtProvince: "", //省份编码",
        rgtProvinceName: "", //省份名称",
        rgtCity: "", //市编码",
        rgtCityName: "", //市名称",
        rgtCounty: "", //"区县编码",
        rgtCountyName: "", //"区县名称",
        rgtTown: "", //"乡镇街道编码",
        rgtTownName: "", //"乡镇街道名称",
        rgtAreaName: "", //"地区名称（省份名称+市名称+区县名称）",
        rgtPermanentAddress: "", // "详细地址",
        // 现居地址
        province: "", //"省份编码",
        provinceName: "", //" 省份名称",
        city: "", //" 市编码",
        cityName: "", //" 市名称",
        county: "", //" 区县编码",
        countyName: "", //" 区县名称",
        town: "", //" 乡镇街道编码",
        townName: "", //" 乡镇街道名称",
        areaName: "", //" 地区名称（省份名称+市名称+区县名称）",
        permanentAddress: "", // " 详细地址",
        // 通讯地址
        postalProvince: "", //" 省份编码",
        postalProvinceName: "", //" 省份名称",
        postalCity: "", //" 市编码",
        postalCityName: "", //" 市名称",
        postalCounty: "", //" 区县编码",
        postalCountyName: "", //" 区县名称",
        postalTown: "", //" 乡镇街道编码",
        postalTownName: "", //" 乡镇街道名称",
        postalAreaName: "", //" 地区名称（省份名称+市名称+区县名称）",
        postalPermanentAddress: "", // " 详细地址",
        // 家庭地址
        homeProvince: "", //" 省份编码",
        homeProvinceName: "", //" 省份名称",
        homeCity: "", //" 市编码",
        homeCityName: "", //" 市名称",
        homeCounty: "", //" 区县编码",
        homeCountyName: "", //" 区县名称",
        homeTown: "", //" 乡镇街道编码",
        homeTownName: "", //" 乡镇街道名称",
        homeAreaName: "", //" 地区名称（省份名称+市名称+区县名称）",
        homePermanentAddress: "", // " 详细地址",
        renewalCount: "", //"港澳通行证换证次数",
        residentType: "", //"居民类型：城镇居民、农村居民",
        residentTypeName: "",
        childrenNum: "", //"投保人子女个数",
        taxIdentInfo: {
          crsSurName: "",
          crsName: "",
          crsHomeNativePlace: "",
          crsHomeProvince: "",
          crsHomeCity: "",
          crsHomeCounty: "",
          crsHomeAddress: "",
          crsEnHomeNativePlace: "",
          crsEnHomeAddress: "",
          crsBirthNativePlace: "",
          crsBirthProvince: "",
          crsBirthCity: "",
          crsBirthCounty: "",
          crsBirthAddress: "",
          crsEnBirthNativePlace: "",
          crsEnBirthAddress: "",
          taxIdentDetail: [],
        },
        relationToMain: "", //"被保人与主被保人关系",
        relationToMainName: "",
        relationToInsured: "", //"受益人与被保人关系",
        relationToAppnt: "", //"受益人与投保人关系",
        relationToAppntName: "",
        bnfType: "", //"受益人类型",
        beneficialGrade: "", // "受益人级别",
        beneficialOrder: "", //"受益人顺序",
        beneficialRate: "", //"受益比例",
        addressTypeNo: "2", //"地址序号0：同投保人;1：同被保人;2：其他",
        relationsWithAppnt: "", //"被保人与投保人关系",
        guardianName: "", //"监护人姓名",
        guardianIdNo: "", //"监护人身份证",
        guardianRelationToInsured: "", // "监护人和被保人关系",
        guardianRelationToInsuredName: "",
        healthyStatus: "",
      },
      // 提示信息
      tipsInfo: {
        name: "",
        idType: "",
        idNum: "",
        validDate: "",
        validDateEnd: "",
        sex: "",
        birthDate: "",
        age: "",
        height: "",
        weight: "",
        maritalStatus: "",
        degree: "",
        phone: "",
        email: "",
        nationality: "",
        nationalityName: "",
        zipCode: "",
        crsIdType: "",
        socialInsuFlag: "",
        grpName: "",
        partTimeJob: "",
        jobContent: "",
        income: "",
        incomeSource: "",
        familyIncome: "",
        familyIncomeSource: "",
        otherCompanyCompIns: "",
        occupationCode: "",
        rgtProvince: "",
        rgtProvinceName: "",
        rgtCity: "",
        rgtCityName: "",
        rgtCounty: "",
        rgtCountyName: "",
        rgtTown: "",
        rgtTownName: "",
        rgtAreaName: "",
        rgtPermanentAddress: "",
        province: "",
        provinceName: "",
        city: "",
        cityName: "",
        county: "",
        countyName: "",
        town: "",
        townName: "",
        areaName: "",
        permanentAddress: "",
        postalProvince: "",
        postalProvinceName: "",
        postalCity: "",
        postalCityName: "",
        postalCounty: "",
        postalCountyName: "",
        postalTown: "",
        postalTownName: "",
        postalAreaName: "",
        postalPermanentAddress: "",
        // 阳光
        homeAreaName: "",
        homeProvince: "",
        homeProvinceName: "",
        homeCity: "",
        homeCityName: "",
        homeCounty: "",
        homeCountyName: "",
        homePermanentAddress: "",
        renewalCount: "",
        residentType: "",
        childrenNum: "",
        taxIdentInfo: {
          crsSurName: "",
          crsName: "",
          crsHomeNativePlace: "",
          crsHomeProvince: "",
          crsHomeCity: "",
          crsHomeCounty: "",
          crsHomeAddress: "",
          crsEnHomeNativePlace: "",
          crsEnHomeAddress: "",
          crsBirthNativePlace: "",
          crsBirthProvince: "",
          crsBirthCity: "",
          crsBirthCounty: "",
          crsBirthAddress: "",
          crsEnBirthNativePlace: "",
          crsEnBirthAddress: "",
          taxIdentDetail: [],
        },
        relationToInsured: "", //"受益人与被保人关系",
        relationToAppnt: "", //"受益人与投保人关系",
        bnfType: "", //"受益人类型",
        beneficialGrade: "", // "受益人级别",
        beneficialOrder: "", //"受益人顺序",
        beneficialRate: "", //"受益比例",
        addressTypeNo: "2", //"地址序号0：同投保人;1：同被保人;2：其他",
        relationsWithAppnt: "", //"被保人与投保人关系",
        relationToMain: "",
        guardianName: "", //"监护人姓名",
        guardianIdNo: "", //"监护人身份证",
        guardianRelationToInsured: "", // "监护人和被保人关系",
        healthyStatus: "",
      },

      showFile: false,
      pageLoad: false, //页面已加载
      showEmailAppend: false, //邮箱后缀自动补全

      showUserList: false,
      validDateDisabled: false,
      validDateStartDisabled: false,
      refname: "",
      refidNum: "",
      refidType: "",
      refvalidDate: "",
      refvalidDateEnd: "",
      refemail: "",
      refphone: "",
      refzipCode: "",
      refpermanentAddress: "",
      refsocialInsuFlag: "",
      refcrsIdType: "",
      refincome: "",
      refgrpName: "",
      foI: false,
      foI2: false,
      refweight: "",
      refheight: "",
      refoccupationCode: "",
      refrelationToAppnt: "",
      refbeneficialOrder: "",
      refbeneficialRate: "",
      refrelationToInsured: "",
      refotherCompanyCompIns: "",
      refposition: "",
      refpartTimeJob: "",
      inputAlign: "right",
      postSameHome: "", //通讯地址同居住地址
      homeSamePostal: "", //家庭地址同通讯地址
      showSheet: false, //选择sheet显示
    };
  },
  computed: {
    ...mapGetters({
      nationList: "dictionary/nationList",
      sexList: "dictionary/sexList",
      customerInfos: "dictionary/customerInfos",
      socialSecList: "dictionary/socialSecList",
      maritalStatusList: "dictionary/maritalStatusList",
      fastmaritalStatus: "dictionary/fastmaritalStatus",
      degreeList: "dictionary/degreeList",
      fastDegree: "dictionary/fastDegree",
      residentTypeList: "dictionary/residentTypeList",
      crsIdTypeList: "dictionary/crsIdTypeList",
      detailAddrRule: "dictionary/detailAddrRule",
      longTime: "dictionary/longTime",
      dateEndList: "dictionary/dateEndList",
      idType3ValidFixed: "dictionary/idType3ValidFixed",
      idType11ValidFixed: "dictionary/idType11ValidFixed",
      inputReg: "infoReg/inputReg",
      hasApiCheckAddr: "page/hasApiCheckAddr",
      revenueFileType: "page/revenueFileType",
      applicant: "insert/applicant",
      appnt: "insert/appnt",
      bbrMultList: "insert/bbrMultList",
      channelType: "insert/channelType",
    }),
    maritalStatusName() {
      let target = this.maritalStatusList.find(
        (item) => item.keyId == this.userInfo.maritalStatus
      );
      if (target) {
        return target.text;
      }
      return "";
    },
    ageVal() {
      if (this.userInfo.birthDate) {
        const uage = this.$GlobalFuns.userAge(this.userInfo.birthDate);
        this.changeData({
          age: uage,
        });
        return uage;
      } else {
        return "";
      }
    },
    // 邮箱后缀自动补全---待使用
    emails() {
      if (!this.userInfo.email) return [];
      const email = this.userInfo.email.trim();
      if (email.includes("@")) {
        this.showEmailAppend = false;
        return [];
      }
      const demoEmails = [
        "@qq.com",
        "@139.com",
        "@163.com",
        "@189.cn",
        "@hotmail.com",
        "@sina.com",
        "@wo.com.cn",
        "@gmail.com",
        "@sohu.com",
        "@yahoo.com",
      ];
      return demoEmails.map((suffix) => email + suffix);
    },
    // 便于同时监听证件类型和证件号的变化
    idTypeNum() {
      return this.userInfo.idNum + this.userInfo.idName;
    },
    /**影响证件有效期的参数 */
    relatDateEnd() {
      return (
        this.userInfo.idNum +
        this.userInfo.idName +
        this.userInfo.birthDate +
        this.userInfo.idType
      );
    },
    cpCompute: {
      get: function () {
        if (this.foI) {
          return this.userInfo.idNum;
        }
        return idNumFormat(this.userInfo.idNum);
      },
      set: function (val) {
        this.changeData({
          idNum: val.toUpperCase(),
        });
        // this.userInfo.idNum = val.toUpperCase()//转大小写的方法
      },
    },
    cpPhoneNum: {
      get: function () {
        if (this.foI2) {
          return this.userInfo.phone;
        }
        return tellPhoneFormat(this.userInfo.phone);
      },
      set: function (val) {
        this.changeData({
          phone: val.replace(/\s*/g, ""),
        });
      },
    },
    showLonger() {
      let flag = true;
      if (this.ageVal <= 45 && this.userInfo.idType == "0") {
        flag = false;
      }
      // 临时身份证  台湾居民来往大陆通行证最多10年  港澳台居民居住证最多5年  外国人永久居留证最多10年   港澳居民来往内地通行证最多10年  护照无长期
      if (
        ["17", "23", "20", "16", "21", "1"].indexOf(this.userInfo.idType) !== -1
      ) {
        flag = false;
      }
      if (
        (this.userInfo.idType == "3" && this.idType3ValidFixed !== -1) ||
        (this.userInfo.idType == "11" && this.idType11ValidFixed !== -1)
      ) {
        flag = false;
      }
      return flag;
    },
    relationVal() {
      if (this.userInfo.relationToAppnt) {
        return this.userInfo.relationToAppnt;
      }
      if (this.userInfo.relationToInsured) {
        return this.userInfo.relationToInsured;
      }
      return "";
    },
    disabledSex() {
      if (
        ["0", "3", "20", "29", "8"].includes(this.userInfo.idType.toString())
      ) {
        return true;
      }
      return false;
    },
    // 便于同时监听多个地址
    xianjuAddress() {
      let res1 = `${this.userInfo.areaName || ""}${
        this.userInfo.permanentAddress || ""
      }`;
      return res1;
    },
    // 通讯
    tongXunAddress() {
      let res2 = `${this.userInfo.postalAreaName || ""}${
        this.userInfo.postalPermanentAddress || ""
      }`;
      return res2;
    },
    // 家庭
    jiaTingAddress() {
      let res3 = `${this.userInfo.homeAreaName || ""}${
        this.userInfo.homePermanentAddress || ""
      }`;
      return res3;
    },

    disEditFields() {
      let res = false;
      if (this.channelType == "3") {
        res = true;
      }
      return res;
    },
  },
  watch: {
    idTypeNum(val) {
      /**
       *  监听证件类型&证件号
       * 如果是0身份证和3户口本，29港澳 8台居民居住证 计算出生日期 和性别
       */
      if (
        this.disabledSex &&
        this.userInfo.idNum &&
        this.userInfo.idNum.length == 18
      ) {
        let get1bs = getBirthSex(this.userInfo.idNum);
        this.userInfo.birthDate = get1bs.birthDate;
        this.userInfo.sex = get1bs.sex;
        this.userInfo.sexName = get1bs.sexName;
      }
    },
    relatDateEnd() {
      // 为空，才赋值
      // if (this.userInfo.validDateEnd) return;
      this.validDateDisabled = false;
      this.validDateStartDisabled = false;
      const handleIdType = (validFixed, birthDate, validFixedMap) => {
        if (!isDateString(birthDate)) {
          console.error("Invalid birthDate format");
          return;
        }
        this.userInfo.validDate = birthDate;
        if (validFixed === 9999) {
          this.setValidEnd("长期");
        } else if (validFixed in validFixedMap) {
          const [age, offset] = validFixedMap[validFixed];
          this.getValidEnd(age, offset);
        }
      };

      const validFixedMapType3 = {
        1: [16, -1], // 证件有效期止期为 16周岁前一天
        2: [16, 0], // 出生日期+16
        9999: "长期", // 长期
      };
      const validFixedMapType11 = {
        1: [3, -1], // 证件有效期止期为 3周岁前一天
        2: [2, 0], // 出生日期+2
        3: [3, 0], // 出生日期+3
        4: [4, -1], // 证件有效期止期为4周岁前一天
        9999: "长期", // 长期
      };
      if (
        this.userInfo.idType == "3" &&
        this.idType3ValidFixed !== -1 &&
        this.userInfo.idNum.length == 18
      ) {
        handleIdType(
          this.idType3ValidFixed,
          this.userInfo.birthDate,
          validFixedMapType3
        );
      } else if (
        this.userInfo.idType == "11" &&
        this.idType11ValidFixed !== -1
      ) {
        handleIdType(
          this.idType11ValidFixed,
          this.userInfo.birthDate,
          validFixedMapType11
        );
      }
    },
    // 无name字段赋值
    "userInfo.degree": {
      handler: function (val) {
        if (!this.infoReg.hasOwnProperty("degree")) return;
        if (!this.userInfo.degreeName) {
          const fdObj = this.degreeList.find((ele) => ele.keyId == val);
          if (fdObj) {
            this.userInfo.degreeName = fdObj.text;
          }
        }
      },
    },
    "userInfo.maritalStatus": {
      handler: function (val) {
        if (!this.infoReg.hasOwnProperty("maritalStatus")) return;
        if (!this.userInfo.maritalStatusName) {
          const fdObj = this.maritalStatusList.find((ele) => ele.keyId == val);
          if (fdObj) {
            this.userInfo.maritalStatusName = fdObj.text;
          }
        }
      },
    },
    // 身份证类型文字获取
    "userInfo.idType": {
      handler: function (val) {
        if (!this.infoReg.hasOwnProperty("idType")) return;
        if (val) {
          const fdObj = this.idTypeList.find((ele) => ele.keyId == val);
          if (fdObj) {
            if (fdObj.text !== this.userInfo.idName) {
              this.userInfo.idName = fdObj.text;
            }
          } else {
            this.userInfo.idName = "";
            this.userInfo.idType = "";
          }
        } else {
          this.userInfo.idName = "";
        }
      },
    },
    tongXunAddress(val) {
      if (val && val == this.xianjuAddress) {
        this.postSameHome = 1;
      } else {
        this.postSameHome = 0;
      }
    },
    jiaTingAddress(val) {
      if (val && val == this.tongXunAddress) {
        this.homeSamePostal = 1;
      } else {
        this.homeSamePostal = 0;
      }
    },
  },
  methods: {
    formatter(value) {
      if (value === null || value === undefined) {
        return "";
      }
      // 将 value 转换为字符串
      value = String(value);
      return value.replace(/\D/g, "");
    },
    validInfo(str) {
      let res = {
        status: true,
        breakTips: "",
        msg: "",
        target: "",
      };
      switch (str) {
        case "name":
          if (!this.userInfo.name) return;
          res = nameCheckRule(this.userInfo.name);
          break;
        case "idNum":
          if (!this.userInfo.idNum) return;
          res = idNumCheck(this.userInfo);
          break;
        case "email":
          if (!this.userInfo.email) return;
          res = emailCheck(this.userInfo);
          break;
        case "permanentAddress":
          if (!this.userInfo[str]) return;
          res = addrCheck(this.userInfo, str);
          break;
        default:
          console.warn(`Unknown validation type: ${str}`);
          return;
      }
      let message = res.breakTips || res.msg;
      if (res.status === false && res.target) {
        const id = `ref${res.target}`;
        this[id] = res.msg;
      }
      if (message) {
        this.$toast(message);
        return;
      }
      // 姓名查留存
      if (
        str == "name" &&
        this.userInfo.name &&
        !this.userInfo.idNum &&
        this.customerInfos === "1"
      ) {
        this.$store
          .dispatch("apis/rakeThroughApi", {
            workNum: this.workNum,
            userId: this.bldUserId,
            name: this.userInfo.name,
          })
          .then((res) => {
            if (res.list && res.list.length > 0) {
              this.openDirectory(this.userInfo.name);
            }
          });
      }
      // 证件号年龄查双录
      if (
        str == "idNum" &&
        this.userType === "投保人" &&
        this.isNetInsure == "2"
      ) {
        const idNum = this.userInfo.idNum;
        const birthDate = idNum.substring(6, 14);
        const year = birthDate.substring(0, 4);
        const month = birthDate.substring(4, 6);
        const day = birthDate.substring(6, 8);
        this.doubleInputs(`${year}-${month}-${day}`);
      }
    },
    initDefaultData() {
      // 给switch类型赋值
      if (
        hasProperty(this.infoReg, "socialInsuFlag") &&
        !this.userInfo.socialInsuFlag
      ) {
        this.userInfo.socialInsuFlag = "Y";
      }
      // 给证件类型的赋值
      if (hasProperty(this.infoReg, "idType")) {
        if (!this.userInfo.idType || this.idTypeList.length == 1) {
          this.changeData({
            idType: this.idTypeList[0].keyId,
            idName: this.idTypeList[0].text,
          });
        }
      }
      if (
        hasProperty(this.infoReg, "crsIdType") &&
        this.crsIdTypeList.length == 1
      ) {
        this.changeData({
          crsIdType: this.crsIdTypeList[0].keyId,
          crsIdTypeName: this.crsIdTypeList[0].text,
        });
      }
      // 国籍
      if (
        hasProperty(this.infoReg, "nationality") &&
        !this.userInfo.nationality
      ) {
        const fd_chn = this.nationList.find(e => e.keyId == 'CHN')
        let gjObj = {}
        if(fd_chn){
          gjObj.nationality = fd_chn.keyId
          gjObj.nationalityName = fd_chn.text
        }else{
          gjObj.nationality = this.nationList[0].keyId
          gjObj.nationalityName = this.nationList[0].text
        }
        this.changeData(gjObj);
      }
      if (hasProperty(this.infoReg, "guardianRelationToInsured")) {
        if (
          this.userInfo.guardianRelationToInsured != "" &&
          this.bbrRelaToJhr.length > 0
        ) {
          const find2Obj = this.bbrRelaToJhr.find(
            (item) => item.keyId == this.userInfo.guardianRelationToInsured
          );
          if (find2Obj) {
            this.changeData({
              guardianRelationToInsured: find2Obj.keyId,
              guardianRelationToInsuredName: find2Obj.text,
            });
          }
        }
      }
      // 婚姻
      if (
        hasProperty(this.infoReg, "maritalStatus") &&
        this.userInfo.maritalStatus === ""
      ) {
        // 投保人婚姻默认已婚
        const maritalStatus = this.userType.includes("投保人") ? "1" : "0";
        this.changeData({
          maritalStatus,
          maritalStatusName: maritalStatus === "1" ? "已婚" : "未婚",
        });
      }
      // 地址同按钮赋值
      this.setSameAddrBtn();
    },
    // 地址同按钮赋值
    setSameAddrBtn() {
      this.postSameHome = "";
      this.homeSamePostal = "";
      const getFullAddress = (areaName, address) => {
        return `${areaName || ""}${address || ""}`;
      };
      const addr_xj = getFullAddress(
        this.userInfo.areaName,
        this.userInfo.permanentAddress
      );
      const addr_tx = getFullAddress(
        this.userInfo.postalAreaName,
        this.userInfo.postalPermanentAddress
      );
      const addr_jt = getFullAddress(
        this.userInfo.homeAreaName,
        this.userInfo.homePermanentAddress
      );
      if (this.infoReg.hasOwnProperty("postalAreaName")) {
        if (addr_xj && addr_tx && addr_xj === addr_tx) {
          this.postSameHome = 1;
        }
      }
      if (this.infoReg.hasOwnProperty("homeAreaName")) {
        if (addr_jt && addr_tx && addr_jt === addr_tx) {
          this.homeSamePostal = 1;
        }
      }
    },
    setMaritalStatus() {
      // 给婚姻关系赋值
      if (this.infoReg.hasOwnProperty("maritalStatus")) {
        // 1已婚 0未婚  10有配偶 11无配偶
        let target = this.maritalStatusList[0];
        // 配偶 父母
        if (["0", "1", "11"].includes(this.relationVal)) {
          this.changeData({
            maritalStatus: target.keyId,
            maritalStatusName: target.text,
          });
        }
        if (this.ageVal < 20 && this.ageVal > 0) {
          target = this.maritalStatusList[1];
          this.changeData({
            maritalStatus: target.keyId,
            maritalStatusName: target.text,
          });
        }
      }
    },
    // 证件照OCR识别
    sureOcrRes(data) {
      // console.log("sureOcrRes---", data);
      if (!data || typeof data !== "object") {
        this.showSheet = false;
        return;
      }
      // 提交图片前,校验证件号
      let res = {
        breakTips: "",
        msg: "",
      };
      if (data.idNum) {
        data.idType = "0";
        res = idNumCheck(data);
      }
      let message = res.breakTips || res.msg;
      if (message) {
        return this.$toast(message);
      }
      // 批量更新属性
      const updateFields = [
        "name",
        "sex",
        "sexName",
        "validDate",
        "validDateEnd",
        "idNum",
        "birthDate",
      ];
      const changes = {};
      for (let field of updateFields) {
        if (field in data && data[field] !== undefined) {
          changes[field] = data[field];
          if (field === "validDateEnd") {
            this.refvalidDateEnd = "";
          }
        }
      }
      if (Object.keys(changes).length > 0) {
        this.changeData(changes);
      }
      this.showSheet = false;
    },
    hideAppend() {
      setTimeout(() => {
        this.showEmailAppend = false;
      }, 30);
    },
    changeData(data) {
      Object.assign(this.userInfo, data);
      this.$forceUpdate();
    },
    /**
     *获取证件有效期止期
     */
    getValidEnd(age, day) {
      // console.log("计算出生日期", age, day)
      if (!this.userInfo.birthDate) {
        return false;
      }
      this.userInfo.validDateEnd = countYearDayForAge(
        this.userInfo.birthDate,
        age,
        day
      );
      // 不设置禁止选择
      this.validDateDisabled = true;
      this.validDateStartDisabled = true;
    },
    setValidEnd() {
      this.userInfo.validDateEnd = this.longTime;
      this.validDateDisabled = true;
    },
    goBackTop() {
      this.$backRouter();
    },
    // 通讯录导入
    async sureUserSelect(user) {
      const filterArr = [
        "taxIdentInfo",
        "crsIdType",
        "crsIdTypeName",
        "relationToAppnt",
        "relationToMain",
        "beneficialOrder",
        "beneficialRate",
        "relationToInsured",
      ];
      const addrs =await this.$store.dispatch("json/getAreaJson",'0');
      let keysValue = {};

      for (const key in user) {
        if (filterArr.includes(key) || !this.infoReg.hasOwnProperty(key))
          continue;
        const value = user[key];
        if (value === "" || value === undefined) continue;
        keysValue[key] = value;
        // 区域
        if (areaCodesMapping.includes(key) && !user[`${key}Name`]) {
          const addrName = getCodeName(value, addrs) || "";
          keysValue[`${key}Name`] = addrName;
        }
        // 其它字段
        if (keyNameListMapping.hasOwnProperty(key)) {
          const [keyName, keyList] = keyNameListMapping[key];
          if (!user[`${keyName}`] && Array.isArray(this[keyList])) {
            keysValue[keyName] =
              this[keyList]?.find((f) => f.keyId === user[key])?.text || "";
          }
        }
      }
      // console.log("keysValue", keysValue);
      this.changeData(keysValue);
      this.showUserList = false;
    },
    openDirectory(keyWord = "") {
      if (this.customerInfos !== "1") return;
      this.showUserList = true;
      this.$nextTick(() => {
        this.$refs[`${this.userFlag}CustomerDirectory`].initData(keyWord);
      });
    },
  },
};
